import datetime

from django.shortcuts import render
# Create your views here.
# Create your views here.
import time
from django.views import View
from employee.models import *

class MainView(View):
    def get(self,request):
        return render(request, 'main-personal.html')

class Personal_mainView(View):
    def get(self,request):
        employees = Employee.objects.get(s_id=100002)
        return render(request, 'personal-main.html',{'emp':employees})

class Personal_checkView(View):
    def get(self,request):
        return render(request, 'personal-check.html')

class Personal_vocView(View):
    def get(self,request):
        return render(request, 'personal-vocationmanage.html')

class pc_serveyView(View):
    def get(self,request):
        return render(request, 'pc-servey.html')


class pc_signView(View):
    def get(self,request):
        return render(request, 'pc-sign.html')

class pv_applyView(View):
    def get(self,request):
        return render(request, 'pv-apply.html')


class SigninTimeView(View):
    def post(self,request):
        user_id = request.session.get('s_id')
        emp = Employee.objects.get(s_id=user_id)
        ti = time.strftime(("%H:%M"))
        now = datetime.datetime.now()
        if request.session.get('signintime',None):
            del request.session['signintime']
            request.session['signintime'] = ti
            start_date = datetime.date(now.year,now.month,now.day)
            end_date = datetime.date(now.year,now.month,now.day+1)
            signintime.objects.filter(time__range=(start_date, end_date)).delete()
            sign = signintime(emp=emp,time=now)
            sign.save()
            return render(request, 'personal-check.html')
        request.session['signintime']= ti
        sign = signintime(emp=emp,time=now)
        sign.save()
        return render(request, 'personal-check.html')

class SignoutTimeView(View):
    def post(self,request):
        user_id = request.session.get('s_id')
        emp = Employee.objects.get(s_id=user_id)
        ti = time.strftime(("%H:%M"))
        now = datetime.datetime.now()
        if request.session.get('signouttime',None):
            del request.session['signouttime']
            request.session['signouttime'] = ti
            start_date = datetime.date(now.year,now.month,now.day)
            end_date = datetime.date(now.year,now.month,now.day+1)
            signouttime.objects.filter(time__range=(start_date, end_date)).delete()
            sign = signouttime(emp=emp,time=now)
            sign.save()
            return render(request, 'personal-check.html')
        request.session['signouttime']= ti
        sign = signouttime(emp=emp,time=now)
        sign.save()
        return render(request, 'personal-check.html')